﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMV.DTO;
using Furion.DependencyInjection;
using Furion.FriendlyException;
using Furion;
using Furion.Logging;

namespace TMV.Web.Core.ApiAttribute
{
    public class ExceptionFilter : IGlobalExceptionHandler, ISingleton
	{
		public Task OnExceptionAsync(ExceptionContext context)
		{
			Log.Error(context.Exception.Message);
			return Task.CompletedTask;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="context"></param>
		public void OnException(ExceptionContext context)
        {
            ResultEntity<bool> result = new();
			Log.Error(context.Exception.Message);
			result.Msg = context.Exception.Message;
            context.Result = new OkObjectResult(result);
			//设置异常已经处理,否则会被其他异常过滤器覆盖
			context.ExceptionHandled = true;
        }
    }
}
